<html>

<head>
    <meta charset="UTF-8">
    <title>服务编排编辑页面</title>
    <link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/aui-iconfonts.css" rel="stylesheet" type="text/css">
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script src="../../ffres/dict/all.js" type="text/javascript"></script>
    <a href="" target="_blank" id="commonLink" name="commonLink"></a>

    <script src="../../static/js/uuid.v4.js" type="text/javascript"></script>
    <style>
        table.part-tb td .easyui-combobox {
            /*width: 100px;*/
        }
        table.part-tb {
            border-collapse: collapse;
        }
        table.part-tb+table.part-tb {
            margin-top: 15px;
        }
        table.part-tb .part-op-td {
            text-align: left;
        }
        table.part-tb .part-op {
            color: #1890ff;
        }
        .part-op+.part-op {
            padding-left: 10px;
        }
        table.part-tb td {
            text-align: center;

            border-color: #3c3c3c;
            border-style: solid;
            border-width: 1px;
            font-size: 14px;
            line-height: 32px;
        }
        table.part-tb td .textbox .textbox-text {
            font-size: 14px;
            color:#3c3c3c;
        }
        table.part-tb td.left {
            text-align: left;
        }
        tr.head-color {
            background-color: #5173a0;
        }
        tr.head-color td {
            color : #FFF;
        }

        table.part-tb .selected {
            /* border: 2px solid #1e8de8; */
            background-color: #cde4fc;
        }

        div.part-tb-title-div {
            display: inline-block;
            margin-right: 15px;
            padding:0px;
            font-size:14px;
            text-align:left;
            border: none;
            background-color: white;
            color:#3c3c3c;
        }
        span.part-tb-title {
            font-size: 14px;
        }
    </style>
</head>

<body class="easyui-layout">
	<div data-options="region:'center',split:false" style="width:100%;height:100%;">
        <div style="text-align:left; width:100%;margin: 0 auto;" id="centerPanel">
            <div class="tool-panel" style="width: 100%; height: 26px;margin-bottom: 2px;padding:4px;width:100%;background-color: #ebecee">
                <a onclick="javascript:appendPartTwoRow()" class="easyui-linkbutton" iconCls="aui-icon aui-icon-small aui-iconfont-insert-row-after" plain="true">插入一行</a>
                <a onclick="javascript:removePartTwoRow()" class="easyui-linkbutton" iconCls="aui-icon aui-icon-small aui-iconfont-remove-row" plain="true">删除一行</a>
                <a onclick="javascript:saveTable()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">保存</a>
                <a onclick="validataTable()"  class="easyui-linkbutton" iconCls="icon-ok" plain="true">校验</a>
                <a  class="easyui-linkbutton" iconCls="icon-ok" plain="true">预览</a>
                <span style="color: #40a0ff">模型状态：<span id="validMsg">未校验</span> </span>
            </div>
            <br/>
            <div id="container" style="text-align:center; width:80%;margin: 0 auto;"></div>
        </div>
	</div>

    <script type="text/javascript">
        // 领域服务中间结果表格 行数据 key
        const PARTONE_DATA_KEY = "nodeData"
        // 领域服务编排表格 行数据 key
        const PARTTWO_DATA_KEY = "trData"
        //  领域服务编排表格 条件数据 key
        const PARTTWO_DATA_COND_TEY = "trDataCondData"
        const NEED_PARSE_KEY = "needParse"


        // two header
        const headerTitles = [
            { property: 'num', name: '序号', width: '5%'},
            { property: 'rowOpType', name: '编排操作', width: '12.5%',
                method: "combobox",
                template: '<select class="easyui-combobox" style="width: 100%; height: 25px;" data-options="required:false,editable:false,valueField:\'enname\',textField:\'cnname\',data:ROW_OP_TYPE"></select>'},
            { property: ['rowOpTargetName'], name: '编排领域/服务', width: '25%', dblclick: true , cls: ['left']},
            // { property: 'opServe', name: '编排服务', width: '12.5%', dblclick: true },
            { property: 'rowBranchCondition', condFlag: true,  name: '分支判断', width: '20%', dblclick: true },
            { property: 'rowBranchOpType', condFlag: true,  name: '分支操作', width: '12.5%',
                method: "combobox",
                template: '<select class="easyui-combobox" style="width: 100%; height: 25px;" data-options="required:false,editable:false,valueField:\'enname\',textField:\'cnname\',data:ROW_BRANCH_OP_TYPE"></select>'},
            { property: ['rowBranchTargetName'], condFlag: true,  name: '分支编排领域/服务', width: '25%', dblclick: true , cls: ['left']},
            // { property: 'condOpServe', condFlag: true,  name: '分支编排服务', width: '12.5%', dblclick: true },
        ]
        // uuid 生成函数
        const uuid = function () {
            return uuidv4().replace(/-/g, "").toUpperCase();
        };
        /**
         * 表格渲染实现
         * @param selector 目标容器 选择器  jquery 写法
         * @param partOne 领域服务中间结果表格
         * @param partTwo 领域服务逻辑编排表格
         */
        function renderTable(selector, partOne, partTwo, funcBind) {
            let container = $(selector)
            // 渲染 partOne
            let partOneTb = $('<table class="part-tb part-one" border="1" width="100%"></table>')
            container.append('<div style="position: relative;text-align: left;" ><div class="part-tb-title-div"><span class="part-tb-title"></span>-领域变量表格</div></div><hr class="tbHr">')
            container.append(partOneTb)
            partOneTb.append('<tr class="head-color"><td colspan="8">领域变量</td></tr>')
            let oneLen = partOne.length || 0
            let oneRows = Math.round((oneLen / 8) + 0.4 ) // 渲染的行数  每行展示 8个
            for (let r=0; r<oneRows; r++) {
                let tr = $('<tr></tr>')
                partOneTb.append(tr)
                for (let c=0; c<8; c++) {
                    let idx = r*8 + c
                    let data = partOne[idx]
                    if (data) {
                        let td = $(`<td width="12.5%">${data.varName}</td>`)
                        td.data(PARTONE_DATA_KEY, data)
                        tr.append(td)
                    } else {
                        tr.append('<td width="12.5%"></td>')
                    }

                }
            }

            // 渲染 partTwo
            container.append('<br/><div style="position: relative;text-align: left;" ><div class="part-tb-title-div"><span class="part-tb-title"></span>-服务编排表格</div></div><hr class="tbHr">')
            let partTwoTb = $('<table class="part-tb part-two" border="1" width="100%" ></table>')
            container.append(partTwoTb)
            initPartTwoEventListener(partTwoTb, funcBind)

            //partTwoTb.append('<tr class="head-color"><td colspan="8">服务编排表格</td></tr>')
            let titleTr = $('<tr class="head-color"></tr>')
            partTwoTb.append(titleTr)
            for (let i=0; i<headerTitles.length; i++) {
                titleTr.append(`<td width="${headerTitles[i].width}">${headerTitles[i].name}</td>`)
            }
            // 渲染 数据
            let num = 1
            let partTwoLen = partTwo.length
            for (let r=0; r<partTwoLen; r++) {
                let tr = $('<tr></tr>')
                partTwoTb.append(tr)
                let data = partTwo[r]
                tr.data(PARTTWO_DATA_KEY, data)
                for(let c=0; c<headerTitles.length; c++) {
                    let props = headerTitles[c]
                    if (props.property == 'num') {
                        tr.append(wrapperTd(props, `<td width="${props.width}">${num++}</td>`))
                    } else if (props.template) {
                        renderTemplate(props, tr, getTdValue(props.property, data))
                    } else {
                        tr.append(wrapperTd(props, `<td width="${props.width}">${getTdValue(props.property, data)}</td>`))
                    }
                }
            }
            if (num<10) {
                for (let r=num; r<=10; r++) {
                    const newTr = $('<tr></tr>')
                    for (let i=0; i<headerTitles.length; i++) {
                        const props = headerTitles[i]
                        if (props.template) {
                            renderTemplate(props, newTr, "")
                        } else {
                            newTr.append(i == 0 ? wrapperTd(props, `<td width="${props.width}">${num++}</td>`) : wrapperTd(props, `<td width="${props.width}"></td>`))
                        }
                    }
                    newTr.data(PARTTWO_DATA_KEY, {})
                    partTwoTb.append(newTr)
                }
            }

            // 设置标题
            $('span.part-tb-title').text((funcBind||{}).title || "领域服务")
            // render after
            afterRender()
        }

        function afterRender() {
            $.parser.parse('.part-tb .need-parse')
            // 初始化赋值
            setTimeout(function() {
                $('.part-tb').find('td.need-parse').each(function(index, el) {
                    const needData = $(el).data(NEED_PARSE_KEY)
                    if (!needData) {
                        return;
                    }
                    const tr = $(el).parent('tr');
                    const trData = $(tr).data(PARTTWO_DATA_KEY);
                    const key = needData.key
                    $(el).children().first()[needData.method]({
                        onChange:function(val) {
                            if (trData) {
                                trData[key] = val
                                $(tr).data(PARTTWO_DATA_KEY, trData);
                            }
                        }
                    })
                    $(el).children().first()[needData.method]('setValue', needData.value)
                    $(el).removeClass('need-parse')
                    $(el).data(NEED_PARSE_KEY, null)
                })
            }, 50)
        }
        /**
         * 输入框 td 渲染
         */
        function renderTemplate(props, tr, val) {
            const td = $(wrapperTd(props, `<td class="need-parse" width="${props.width}"></td>`))
            const input = $(props.template)
            td.append(input)
            td.data(NEED_PARSE_KEY, {
                method: props.method,
                value: val,
                key: props.property
            })
            tr.append(td)
        }
        /**
         * 包装 td html 创建
         * 在这里对 td 进行一些处理 包括必要属性的添加
         */
        function wrapperTd(props, tdHtml) {
            const td = $(tdHtml)
            if (props.dblclick) {
                const prop = Array.isArray(props.property) ? props.property.join("_") : props.property
                td.attr("dblclick-prop", prop)
            }
            if (props.cls) {
                td.addClass(props.cls.join(" "))
            }
            return td
        }
        /**
         * 获取 td 单元格的值  根据 property
         */
        function getTdValue(property, data) {
            data = data || {}
            if (Array.isArray(property)) {
                let vals = []
                for (let i=0; i<property.length; i++) {
                    if (data[property[i]]) {
                        vals.push(data[property[i]])
                    }
                }
                return vals.join("-")
            } else {
                return data[property] || ""
            }
        }

        /**
         * 初始化表格事件绑定
         * @param $tb
         */
        function initPartTwoEventListener($tb, funcBind) {
            $($tb).click(function(event){
                if (event.target.nodeName == 'TD') {
                    const parentTr = $(event.target).parent('tr')
                    toggleRowSelect(parentTr)
                } else if (event.target.nodeName == 'TR') {
                    event.preventDefault();
                    event.stopPropagation();
                    toggleRowSelect(parentTr)
                }
            })
            $($tb).dblclick(function(event){
                const prop = $(event.target).attr('dblclick-prop')
                if (event.target.nodeName == 'TD' && prop) {
                    event.preventDefault();
                    event.stopPropagation();
                    const parentTr = $(event.target).parent('tr')
                    const data = $(parentTr).data(PARTTWO_DATA_KEY)
                    const condData = $(parentTr).data(PARTTWO_DATA_COND_TEY)
                    const newData = Object.assign({}, condData, data)
                    if (funcBind && funcBind.partTwo && funcBind.partTwo[prop] && funcBind.partTwo[prop].dblclick) {
                        funcBind.partTwo[prop].dblclick.call(event.target, prop, newData, parentTr, event.target)
                    }
                }
            })
        }

        /**
         * 处理表格行选中
         * @param tr
         */
        function toggleRowSelect(tr) {
            $(tr).parents('table').find('tr.selected').not(tr).removeClass('selected');
            $(tr).not('tr.part-op-tr').not('tr.head-color').toggleClass('selected');
        }

        /**
         *  获取选中行  如没有选中行  返回 null
         */
        function getSelectedRow($tb) {
            const selected = $tb.find('tr.selected')
            if (selected && selected.length > 0) {
                return selected
            } else {
                return null
            }
        }

        /**
         * 处理删除行
         */
        function deleteRow($tb) {
            const selected = getSelectedRow($tb)
            if (selected) {
                $.messager.confirm('删除提示', '你确定要删除这一行?', function (r) {
                    if (r) {
                        let num = $(selected).children().first().text() * 1
                        $(selected).nextAll().each(function(index, el) {
                            const data = $(el).data(PARTTWO_DATA_KEY)
                            if (data) {
                                $(el).children().first().text(num++)
                            }
                        })
                        const selectedRow = $(selected).data(PARTTWO_DATA_KEY)
                        if (selectedRow.tableRowId) {
                            $.restfulDelete('../../api/osrv/arrange/table', {tableRowId : selectedRow.tableRowId}, function(data) {
                                // $.messager.alert('提示','记录删除成功!','info');
                            });
                        }
                        $(selected).data(PARTTWO_DATA_KEY, null)
                        selected.remove()
                    }
                });
            } else {
                $.messager.alert('提示','请选择一行！','info');
            }
        }

        /**
         * 在选中行后面插入一行
         */
        function appendRow($tb) {
            const selected = getSelectedRow($tb)
            if (selected) {
                const selectedData = $(selected).data(PARTTWO_DATA_KEY)
                let num = $(selected).children().first().text() * 1
                num = num + 1
                const newTr = $('<tr></tr>')
                for (let i=0; i<headerTitles.length; i++) {
                    const props = headerTitles[i]
                    if (props.template) {
                        renderTemplate(props, newTr, "")
                    } else {
                        newTr.append(i == 0 ? wrapperTd(props, `<td width="${props.width}">${num++}</td>`) : wrapperTd(props, `<td width="${props.width}"></td>`))
                    }
                }
                newTr.data(PARTTWO_DATA_KEY, {})
                selected.after(newTr)
                newTr.nextAll().each(function(index, el) {
                    const data = $(el).data(PARTTWO_DATA_KEY)
                    if (data) {
                        $(el).children().first().text(num++)
                    }
                })
                afterRender()
            } else {
                $.messager.alert('提示','请选择一行！','info');
            }
        }

        function appendPartTwoRow() {
            const $tb = $('table.part-tb.part-two')
            appendRow($tb)
        }
        function removePartTwoRow() {
            const $tb = $('table.part-tb.part-two')
            deleteRow($tb)
        }

        function exportPartTwo() {
            const $tb = $('table.part-tb.part-two')
            let exportData = []
            $tb.find('tr').each(function(index, tr){
                const data = $(tr).data(PARTTWO_DATA_KEY)
                if (data) {
                    const num = $(tr).children('td').first().text()
                    data.tableRowNo = num;
                    const obj = Object.assign({}, data)
                    if (Object.keys(obj).length > 1) {
                        exportData.push(obj)
                    }
                }
            })
            return exportData
        }

    </script>
    <script>
        var appId = $.getUrlParam('appId');
        var externalData, flow, currentNode;
        var appModelId = $.getUrlParam('appModelId');
        var title = ""
        var targetTr = null, targetTd = null, targetProp = null;
        $(function () {
            $.restfulGet('../../api/app/model/info/' + appModelId ,null,function(data){
                renderTableTitle(data.rows)
            });
            var fixWindowHeight = function(){
                var h = $(window).height();
                var w = $(window).width();
            };
            $(window).on('resize', fixWindowHeight);
            $.restfulPostJson('../../api/osrv/arrange/data', { appModelId: appModelId},
                function (data) {
                    externalData = data.rows;
                    initTable();
                    fixWindowHeight();
                }, "json");

            // ctrl + s save
            window.addEventListener("keydown", function(event) {
                if (!(event.which == 83 && event.ctrlKey)) return true;
                event.preventDefault();
                saveTable();
                return false;
            });
        });

        /**
         * 展示表格标题
         */
        function renderTableTitle(appModelInfo) {
            $.restfulGet('../../api/paas/sys/tree/' + appModelInfo.appId ,null,function(data){
                let appModelName = appModelInfo.appModelName;
                title = `${data.rows.packageName}-${appModelName}`
                $('title').text(title);
                $('#title').text(title);
            });
        }

        /**
         * 渲染表格
         */
        function initTable() {
            let partOne = externalData.OsrvArrangeVarVO
            let partTwo = externalData.OsrvArrangeTableVO


            renderTable('#container', partOne, partTwo, {
                title: title,
                partTwo: {
                    rowOpTargetName: {
                        dblclick: function(prop, data, tr, td) {
                            targetTr = tr
                            targetTd = td
                            targetProp = "rowOpTargetId"
                            if (data[targetProp]) {
                                if (!data.tableRowId) {
                                    // 没有 id 生成
                                    data.tableRowId = uuid();
                                    $(tr).data(PARTTWO_DATA_KEY, data)
                                    // 初始关联参数列表
                                    $.restfulPostJson(`../../api/osrv/isrv/evals/tableInit?appModelId=${data.rowOpTargetId}`,
                                        {nodeId: data.tableRowId}, function(data){}, null, true)
                                }
                                // 已经选择了
                                if (data.rowOpType == 'C') {
                                    // 服务调用
                                    JLEUtil.createModalWin(`${data.rowOpTargetName}调用赋值`, `AppModelInfo-ArrangeTable.html?appId=${appId}&appModelId=${data[targetProp]}&nodeId=${data.tableRowId}&readonly=false`);
                                } else if (data.rowOpType == 'E') {
                                    // 领域赋值
                                    $.restfulGet('../../api/osrv/arrange/var/' + appModelId + '/' + data[targetProp], null,function(varData){
                                        if (varData.rows.varType == "I") {
                                            // 入参
                                            JLEUtil.createModalWin(`${data.rowOpTargetName}列表信息`,
                                                `OsrvInoutInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&nodeType=00&readonly=false`);
                                        } else if (varData.rows.varType == "O") {
                                            // 出参
                                            JLEUtil.createModalWin(`${data.rowOpTargetName}列表信息`,
                                                `OsrvInoutInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&nodeType=99&readonly=false`);
                                        } else if (varData.rows.varType == "D") {
                                            // 领域变量
                                            JLEUtil.createModalWin(`${data.rowOpTargetName}列表信息`,
                                                `OsrvTranInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&readonly=false`);
                                        }
                                    }, null, true);
                                } else {
                                    // 领域校验
                                    JLEUtil.createModalWin(`${data.rowOpTargetName}列表信息`,
                                        `OsrvValidateInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&readonly=false`);
                                }
                            } else {
                                if (data.rowOpType == 'C') {
                                    // 服务调用
                                    JLEUtil.createModalWin('选择服务', `popAppModelInfo-I01.html?appId=${appId}&returnFunc=appModelSelected`);
                                } else if (data.rowOpType == 'E') {
                                    // 领域赋值
                                    JLEUtil.createModalWin('选择领域变量', `popOsrvArrangeVar.html?appId=${appId}&appModelId=${appModelId}&returnFunc=varSelected`);
                                } else {
                                    // 领域校验
                                    JLEUtil.createModalWin('选择领域变量', `popOsrvArrangeVar.html?appId=${appId}&appModelId=${appModelId}&returnFunc=varSelected`);
                                }
                            }
                        }
                    },
                    rowBranchCondition: {
                        dblclick: function(prop, data, tr, td) {
                            targetTr = tr
                            targetTd = td
                            if (data.rowOpType == 'C' && data.rowOpTargetId) {
                                if (!data.tableRowId) {
                                    // 没有 id 生成
                                    data.tableRowId = uuid();
                                    $(tr).data(PARTTWO_DATA_KEY, data)
                                }
                                if (data.rowBranchCondition) {
                                    JLEUtil.createModalWin('外部模型节点链接条件列表', `OsrvLinkedCondUpdate-Table.html?dialog=show&appId=${appId}&appModelId=${data.rowOpTargetId}&linkedId=${data.tableRowId}&readonly=false`);
                                } else {
                                    JLEUtil.createModalWin('外部模型节点链接条件列表', `OsrvLinkedCondAdd-Table.html?dialog=show&appId=${appId}&appModelId=${data.rowOpTargetId}&linkedId=${data.tableRowId}&readonly=false`);
                                }
                            }
                        }
                    },
                    rowBranchTargetName: {
                        dblclick: function(prop, data, tr, td) {
                            targetTr = tr
                            targetTd = td
                            targetProp = "rowBranchTargetId"
                            if (data[targetProp]) {
                                if (!data.tableRowId) {
                                    // 没有 id 生成
                                    data.tableRowId = uuid();
                                    $(tr).data(PARTTWO_DATA_KEY, data)
                                    // 初始关联参数列表
                                    $.restfulPostJson(`../../api/osrv/isrv/evals/tableInit?appModelId=${data.rowBranchTargetId}`,
                                        {nodeId: data.tableRowId}, function(data){}, null, true)
                                }
                                // 已经选择了
                                if (data.rowOpType == 'C') {
                                    // 服务调用
                                    JLEUtil.createModalWin(`${data.rowBranchTargetName}调用赋值`, `AppModelInfo-ArrangeTable.html?appId=${appId}&appModelId=${data[targetProp]}&nodeId=${data.tableRowId}&readonly=false`);
                                } else if (data.rowOpType == 'E') {
                                    // 领域赋值
                                    $.restfulGet('../../api/osrv/arrange/var/' + appModelId + '/' + data[targetProp], null,function(varData){
                                        if (varData.rows.varType == "I") {
                                            // 入参
                                            JLEUtil.createModalWin(`${data.rowBranchTargetName}列表信息`,
                                                `OsrvInoutInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&nodeType=00&readonly=false`);
                                        } else if (varData.rows.varType == "O") {
                                            // 出参
                                            JLEUtil.createModalWin(`${data.rowBranchTargetName}列表信息`,
                                                `OsrvInoutInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&nodeType=99&readonly=false`);
                                        } else if (varData.rows.varType == "D") {
                                            // 领域变量
                                            JLEUtil.createModalWin(`${data.rowBranchTargetName}列表信息`,
                                                `OsrvTranInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&readonly=false`);
                                        }
                                    }, null, true);
                                } else {
                                    // 领域校验
                                    JLEUtil.createModalWin(`${data.rowBranchTargetName}列表信息`,
                                        `OsrvValidateInfoList.html?dialog=show&appId=${appId}&appModelId=${appModelId}&nodeId=${data.tableRowId}&readonly=false`);
                                }
                            } else {
                                if (data.rowOpType == 'C') {
                                    // 服务调用
                                    JLEUtil.createModalWin('选择服务', `popAppModelInfo-I01.html?appId=${appId}&returnFunc=appModelSelected`);
                                } else if (data.rowOpType == 'E') {
                                    // 领域赋值
                                    JLEUtil.createModalWin('选择领域变量', `popOsrvArrangeVar.html?appId=${appId}&appModelId=${appModelId}&returnFunc=varSelected`);
                                } else {
                                    // 领域校验
                                    JLEUtil.createModalWin('选择领域变量', `popOsrvArrangeVar.html?appId=${appId}&appModelId=${appModelId}&returnFunc=varSelected`);
                                }
                            }
                        }
                    },
                }
            })
        }

        /**
         * 保存表格
         */
        function saveTable(reload=true) {
            const partTwo = exportPartTwo()
            // 回填 appModelId
            for (let i =0 ; i < partTwo.length; i++) {
                const data = partTwo[i]
                data.appModelId = appModelId
            }
            $.restfulPostJson('../../api/osrv/arrange/savelist', partTwo ,
                function (data) {
                    if (reload) {
                        $.messager.alert('提示', '保存成功', 'info');
                        window.location.reload();
                    }

                }
            );
        }

        /**
         *  校验表格
         */
        function validataTable() {

        }

        /**
         * 内部服务选择返回
         * @param appModelInfoI01
         */
        function appModelSelected(appModelInfoI01) {
            const data = $(targetTr).data(PARTTWO_DATA_KEY)
            if (targetProp == "rowOpTargetId") {
                data.rowOpTargetId = appModelInfoI01.appModelId;
                data.rowOpTargetName = appModelInfoI01.appModelName;
                $(targetTd).text(data.rowOpTargetName)
                $(targetTr).data(PARTTWO_DATA_KEY, data)

            } else if (targetProp = "rowBranchTargetId") {
                data.rowBranchTargetId = appModelInfoI01.appModelId;
                data.rowBranchTargetName = appModelInfoI01.appModelName;
                $(targetTd).text(data.rowBranchTargetName)
                $(targetTr).data(PARTTWO_DATA_KEY, data)
            }
        }

        /**
         * 服务变量选择
         * @param varSelected
         */
        function varSelected(varSelected) {
            const data = $(targetTr).data(PARTTWO_DATA_KEY)
            if (targetProp == "rowOpTargetId") {
                data.rowOpTargetId = varSelected.varId;
                data.rowOpTargetName = varSelected.varName;
                $(targetTd).text(data.rowOpTargetName)
                $(targetTr).data(PARTTWO_DATA_KEY, data)
            } else if (targetProp = "rowBranchTargetId") {
                data.rowBranchTargetId = varSelected.varId;
                data.rowBranchTargetName = varSelected.varName;
                $(targetTd).text(data.rowBranchTargetName)
                $(targetTr).data(PARTTWO_DATA_KEY, data)
            }
        }

        function setCond(cond) {
            const data = $(targetTr).data(PARTTWO_DATA_KEY)
            if (cond.compareTargetType == '1') {
                // 常量
                let condStr = `${cond.condFieldName}${formatter_COND_COMPARE_SIGN(cond.condCompareSign)}${cond.constValue}`
                data.rowBranchCondition = condStr;
            } else {
                let condStr = `${cond.condFieldName}${formatter_COND_COMPARE_SIGN(cond.condCompareSign)}${cond.paramFieldName}`
                data.rowBranchCondition = condStr;
            }
            $(targetTd).text(data.rowBranchCondition)
            saveTable(false)
        }


    </script>
</body>

</html>